/****************************************************
          File Name:stack.c
          Author: Abby Cin
          Mail: abbytsing@gmail.com
          Created Time: Sun 08 Feb 2015 09:16:56 PM CST
*****************************************************/

#include "stack.h"
#include <string.h>

int main(int argc, char *argv[])
{
    Stack *s;

    if(!InitStack(&s)) return -1;
    if(isEmpty(s))
        printf("stack is empty!\n");
    else
        printf("too bad, stack not empty\n");

    printf("enter stack size: ");
    scanf("%d",&MAX);
    getchar(); // eat '\n'

    char e[10];
    for(int i=0; i<MAX; i++)
    {
        printf("Enter a string push to Stack: ");
        memset(e, 0, 10);
        fgets(e, 10, stdin);
        if(!Push(&s, e))
            printf("Push element to Stack failed\n");
    }

    char res[10];
    printf("\n\nStack size: %d (before)\n", StackLength(s));
    printf("pop %d of %d from stack:\n", MAX-1, MAX);
    for(int i=0; i<MAX-1; i++)
    {
        if(!Pop(&s, res))
            printf("failed in Pop()");
        else
            printf("\t\t\tPop: %s", res);
        memset(res, 0, 10);
    }

    printf("Stack size: %d (after)\n\n", StackLength(s));
    if(GetTop(s, res))
    printf("the top element: %s\n",res);
    printf("destory stack...\n");
    DestroyStack(s);
}
